package com.demo.consumer;

import api.AsyncService;
import api.DemoService;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@NacosPropertySource(dataId = "dubbo_consumer", autoRefreshed = true)
@EnableDubbo
@SpringBootApplication
public class DubboConsumerApplication {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Reference
    private DemoService demoService;

    @Reference
    private AsyncService asyncService;

    @NacosValue(value = "${nacos.test}", autoRefreshed = true)
    private String config;

    public DubboConsumerApplication() {
    }

    public static void main(String[] args) {
        SpringApplication.run(DubboConsumerApplication.class, args);
    }
    
    @Bean
    public ApplicationRunner runner() {
        return args -> {
            logger.info("NacosValue:"+config);
            logger.info(demoService.sayHello("Not Sure"));
            logger.info(asyncService.sayHello("Not Sure"));
        };
    }

}
